﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

namespace _2011DBProject
{
    public partial class _Default : System.Web.UI.Page
    {
        //이벤트 순서
        //Page_PreInit;
        //Page_Init;
        //Page_InitComplete;
        //Page_PreLoad;
        //Page_Load;
        //Page_LoadComplete;
        //Page_PreRender;
        //Page_PreRenderComplete;
        //Page_SaveStateComplete;

        #region Methods

        /// <summary>
        /// method to login user
        /// </summary>
        private void Login()
        {
            DataSet1 ds = new DataSet1();
            DataSet1TableAdapters.ACCOUNTTableAdapter taAccount = new DataSet1TableAdapters.ACCOUNTTableAdapter();
            taAccount.Connection.ConnectionString = Settings.strConnectionString;

            taAccount.FillByACCOUNT_ID(ds.ACCOUNT, txtID.Text);

            if (ds.ACCOUNT.Count == 0)
            {
                lblMsg.Text = "계정이 없습니다!";
                lblMsg.Visible = true;
            }
            else if (ds.ACCOUNT[0].PASSWORD == txtPassword.Text)
            {
                lblMsg.Visible = false;
                Session.Add("USER", txtID.Text);
                //Session.Add("SERVER", ddServer.SelectedValue);
                Settings.RefreshSessionVariables(false, false);
                Response.Redirect("Server.aspx");
            }
            else
            {
                lblMsg.Text = "비밀번호가 맞지 않습니다!";
                lblMsg.Visible = true;
            }
        }

        #endregion

        #region Event Handlers

        protected void Button1_Click(object sender, EventArgs e)
        {
            lblMsg.Visible = false;
            Login();
        }
        
        #endregion

        protected void Button1_Click1(object sender, EventArgs e)
        {
            Response.Redirect("Join.aspx");
        }


        protected void Page_Load(object sender, EventArgs e)
        {
            String isJoin = Request.QueryString["isJoin"];
            String isNoSession = Request.QueryString["isNoSession"];

            if (isJoin == "1")
            {
                string script = "<script>alert('계정이 생성되었습니다.!!');</script>";
                Page.ClientScript.RegisterClientScriptBlock(typeof(string), "confirm", script);
                isJoin = "0";
            }
            if (isNoSession == "1")
            {
                lblMsg.Text = "세션이 종료되었거나 비정상적인 접근으로 로그인 페이지로 이동하였습니다";
                isNoSession = "0";
            }

            SetFocus(txtID);

        }

    }
}
